<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="68px">
<!--      <el-form-item label="手牌号" prop="handBrand">
        <el-input
          v-model="queryParams.handBrand"
          placeholder="请输入手牌号"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手牌类别" prop="handCategory">
        <el-select v-model="queryParams.handCategory" placeholder="请选择手牌类别" clearable style="width: 210px">
          <el-option
            v-for="dict in dict.type.yqg_hand_category"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="手牌状态" prop="handState">
        <el-select v-model="queryParams.handState" placeholder="请选择手牌状态" clearable style="width: 210px">
          <el-option
            v-for="dict in dict.type.yqg_hand_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="房间号" prop="roomNumber" >
        <el-input
          v-model="queryParams.roomNumber"
          placeholder="请输入房间号"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="房间号" prop="roomNumber" >
        <el-input
          v-model="queryParams.roomNumber"
          placeholder="请输入房间号"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="房间状态" prop="roomStatus">
        <el-select v-model="queryParams.roomStatus" placeholder="请选择房间状态" clearable style="width: 210px" >
          <el-option
            v-for="dict in dict.type.yqg_room_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="房间类型" prop="roomType">
        <el-select v-model="queryParams.roomType" placeholder="请选择房间状态" clearable style="width: 210px" >
          <el-option
            v-for="dict in dict.type.yqg_room_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--el-form-item v-show="showSearch" label="开房时间" prop="openingHours">
        <el-date-picker clearable
          v-model="queryParams.openingHours"
          type="date"
          value-format="yyyy-MM-dd"
                        style="width: 210px"
          placeholder="请选择开房时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item  v-show="showSearch" label="退房时间" prop="checkOutTime">
        <el-date-picker clearable

          v-model="queryParams.checkOutTime"
          type="date"
                        style="width: 210px"
          value-format="yyyy-MM-dd"
          placeholder="请选择退房时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item v-show="showSearch" label="房间费用" prop="roomCharges">
        <el-input
          v-model="queryParams.roomCharges"
          placeholder="请输入房间费用"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="实际时间" prop="actualTime">
        <el-input
          v-model="queryParams.actualTime"
          placeholder="请输入实际时间"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="收费时间" prop="chargingTime">
        <el-input
          v-model="queryParams.chargingTime"
          placeholder="请输入收费时间"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="剩余时间" prop="timeRemaining">
        <el-input
          v-model="queryParams.timeRemaining"
          placeholder="请输入剩余时间"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="房嫂工号" prop="cleanerNumber">
        <el-input
          v-model="queryParams.cleanerNumber"
          placeholder="请输入房嫂工号"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="叫醒" prop="wakeUp">
        <el-input
          v-model="queryParams.wakeUp"
          placeholder="请输入叫醒"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="服务员" prop="waiter">
        <el-input
          v-model="queryParams.waiter"
          placeholder="请输入服务员"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="技师" prop="artificer">
        <el-input
          v-model="queryParams.artificer"
          placeholder="请输入技师"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="项目名称" prop="entryName">
        <el-input
          v-model="queryParams.entryName"
          placeholder="请输入项目名称"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item v-show="showSearch" label="备注" prop="note">
        <el-input
          v-model="queryParams.note"
        placeholder="请输入备注"
          clearable
          style="width: 210px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
    </el-form>
    <el-form>
      <el-form-item  style="text-align: right;">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['project:room:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['project:room:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" ></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="roomList"  border @selection-change="handleSelectionChange" style="overflow-x: auto;">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="55" :index="indexMethod" align="center"
                       ></el-table-column>
     <!-- <el-table-column label="ID" align="center" prop="ID" /> -->
      <el-table-column label="房间号" align="center" prop="roomNumber"  />

      <el-table-column label="房间状态" align="center" prop="roomStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_room_status" :value="scope.row.roomStatus" />
        </template>
      </el-table-column>
      <el-table-column label="房间类型" align="center" prop="roomType" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.yqg_room_type" :value="scope.row.roomType" />
      </template>
      </el-table-column>
<!--      <el-table-column label="手牌号" align="center" prop="handBrand" v-if="columns[1].visible"/>-->
<!--      <el-table-column label="手牌类别" align="center" prop="handCategory" v-if="columns[2].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_hand_category" :value="scope.row.handCategory"/>
        </template>
      </el-table-column>-->
<!--      <el-table-column label="手牌状态" align="center" prop="handState" v-if="columns[3].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yqg_hand_state" :value="scope.row.handState"/>
        </template>
      </el-table-column>-->

<!--      <el-table-column label="开房时间" align="center" prop="openingHours" v-if="columns[7].visible" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.openingHours, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="退房时间" align="center" prop="checkOutTime" v-if="columns[8].visible" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkOutTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="房间费用" align="center" prop="roomCharges" v-if="columns[9].visible"/>
      <el-table-column label="实际时间" align="center" prop="actualTime" v-if="columns[10].visible" width="180"/>
      <el-table-column label="收费时间" align="center" prop="chargingTime" v-if="columns[11].visible" width="180"/>
      <el-table-column label="剩余时间" align="center" prop="timeRemaining"  v-if="columns[12].visible" />
      <el-table-column label="房嫂工号" align="center" prop="cleanerNumber" v-if="columns[13].visible" />
      <el-table-column label="叫醒" align="center" prop="wakeUp" v-if="columns[14].visible" />
      <el-table-column label="服务员" align="center" prop="waiter" v-if="columns[15].visible" />
      <el-table-column label="技师" align="center" prop="artificer" v-if="columns[16].visible" />
      <el-table-column label="项目名称" align="center" prop="entryName" v-if="columns[17].visible" />
      <el-table-column label="备注" align="center" prop="note" v-if="columns[18].visible" />-->
      <el-table-column label="操作" align="center" fixed="right" class-name="small-padding fixed-width" width="160">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房间基础信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="755px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="115px" :inline="true">
<!--        <el-form-item label="手牌号" prop="handBrand">
          <el-input v-model="form.handBrand" placeholder="请输入手牌号" style="width: 215px" />
        </el-form-item>
        <el-form-item label="手牌类别" prop="handCategory">
          <el-select v-model="form.handCategory" placeholder="请选择手牌类别"  style="width: 215px" >
            <el-option
              v-for="dict in dict.type.yqg_hand_category"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="手牌状态" prop="handState">
          <el-select v-model="form.handState" placeholder="请选择手牌状态" style="width: 215px">
            <el-option
              v-for="dict in dict.type.yqg_hand_state"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>-->
        <el-form-item label="房间号" prop="roomNumber">
          <el-input v-model="form.roomNumber" placeholder="请输入房间号" style="width: 215px"/>
        </el-form-item>

        <el-form-item label="房间类型" prop="roomType">
          <el-select v-model="form.roomType" placeholder="请选择房间状态" clearable style="width: 210px" >
            <el-option
              v-for="dict in dict.type.yqg_room_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="房间状态" prop="roomStatus" style="width: 500px">
          <el-radio-group v-model="form.roomStatus">
            <el-radio
              v-for="dict in dict.type.yqg_room_status"
              :key="dict.value"
              :label="dict.value"
            >{{dict.label}}</el-radio>
          </el-radio-group>
        </el-form-item>
<!--        <el-form-item label="开房时间" prop="openingHours"  >
          <el-date-picker clearable
                          style="width: 215px"
            v-model="form.openingHours"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开房时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="退房时间" prop="checkOutTime">
          <el-date-picker clearable
                          style="width: 215px"
            v-model="form.checkOutTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择退房时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="房间费用" prop="roomCharges" >
          <el-input v-model="form.roomCharges" placeholder="请输入房间费用" style="width: 215px" />
        </el-form-item>
        <el-form-item label="实际时间" prop="actualTime">
          <el-input v-model="form.actualTime" placeholder="请输入实际时间" style="width: 215px"/>
        </el-form-item>
        <el-form-item label="收费时间" prop="chargingTime">
          <el-input v-model="form.chargingTime" placeholder="请输入收费时间"style="width: 215px" />
        </el-form-item>
        <el-form-item label="剩余时间" prop="timeRemaining">
          <el-input v-model="form.timeRemaining" placeholder="请输入剩余时间" style="width: 215px"/>
        </el-form-item>
        <el-form-item label="房嫂工号" prop="cleanerNumber">
          <el-input v-model="form.cleanerNumber" placeholder="请输入房嫂工号" style="width: 215px"/>
        </el-form-item>
        <el-form-item label="叫醒" prop="wakeUp">
          <el-input v-model="form.wakeUp" placeholder="请输入叫醒" style="width: 215px" />
        </el-form-item>
        <el-form-item label="服务员" prop="waiter">
          <el-input v-model="form.waiter" placeholder="请输入服务员" style="width: 215px" />
        </el-form-item>
        <el-form-item label="技师" prop="artificer">
          <el-input v-model="form.artificer" placeholder="请输入技师" style="width: 215px"/>
        </el-form-item>
        <el-form-item label="项目名称" prop="entryName">
          <el-input v-model="form.entryName" placeholder="请输入项目名称" style="width: 215px"/>
        </el-form-item>
        <el-form-item label="备注" prop="note">
          <el-input v-model="form.note" placeholder="请输入备注" style="width: 215px" />
        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRoom, getRoom, delRoom, addRoom, updateRoom } from "@/api/module/zxy/room";

export default {
  name: "Room",
  dicts: ['yqg_hand_category', 'yqg_room_type', 'yqg_room_status'],
  data() {
    return {
      columns: [
        {key: 0, label: `序号`, visible: true},
        {key: 1, label: `手牌号`, visible: true},
        {key: 2, label: `手牌类别`, visible: false},
        {key: 3, label: `手牌状态`, visible: true},
        {key: 1, label: `房间号`, visible: false},
        {key: 5, label: `房间类型`, visible: false},
        {key: 2, label: `房间状态`, visible: false},
        {key: 7, label: `开房时间`, visible: false},
        {key: 8, label: `退房时间`, visible: false},
        {key: 9, label: `房间费用`, visible: true},
        {key: 10, label: `实际时间`, visible: false},
        {key: 11, label: `收费时间`, visible: true},
        {key: 12, label: `剩余时间`, visible: false},
        {key: 13, label: `房嫂工号`, visible: false},
        {key: 14, label: `叫醒`, visible: true},
        {key: 15, label: `服务员`, visible: false},
        {key: 16, label: `技师`, visible: false},
        {key: 17, label: `项目名称`, visible: true},
        {key: 18, label: `备注`, visible: true},
      ],

      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 房间基础信息表格数据
      roomList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        handBrand: null,
        handCategory: null,
        handState: null,
        roomNumber: null,
        roomType: null,
        roomStatus: null,
        openingHours: null,
        checkOutTime: null,
        roomCharges: null,
        actualTime: null,
        chargingTime: null,
        timeRemaining: null,
        cleanerNumber: null,
        wakeUp: null,
        waiter: null,
        artificer: null,
        entryName: null,
        note: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询房间基础信息列表 */
    getList() {
      this.loading = true;
      listRoom(this.queryParams).then(response => {
        this.roomList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        ID: null,
        handBrand: null,
        handCategory: null,
        handState: null,
        roomNumber: null,
        roomType: null,
        roomStatus: null,
        openingHours: null,
        checkOutTime: null,
        roomCharges: null,
        actualTime: null,
        chargingTime: null,
        timeRemaining: null,
        cleanerNumber: null,
        wakeUp: null,
        waiter: null,
        artificer: null,
        entryName: null,
        note: null,
        note1: null,
        note2: null,
        note3: null,
        note4: null,
        note5: null,
        note6: null,
        note7: null,
        note8: null,
        note9: null,
        note10: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加房间基础信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getRoom(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改房间基础信息";
      });
    },
    indexMethod(index) {
      index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
      return index
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateRoom(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addRoom(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除房间基础信息编号为"' + ids + '"的数据项？').then(function() {
        return delRoom(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('project/room/export', {
        ...this.queryParams
      }, `room_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

